/*
 * Copyright 2012 Faculty of Informatics - Masaryk University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.pa165.creatures.rest.backend;

import java.io.InputStream;
import javax.ws.rs.core.Response;

/**
 * Interface which one is obliged to implement in order to provide a way how to
 * deal with CRUD-like operations upon some entity, typically from
 * {@link cz.muni.fi.pa165.creatures.model}.
 *
 * @author xmiklos1
 */
public interface EntityResource {

    /**
     * This method creates an entity.
     *
     * @param data response data
     * @return response as an URI to the just created resource
     * @throws WebApplicationException
     */
    Response create(InputStream data);

    /**
     * This method deletes an entity of specified {@code id}.
     *
     * @param id id of an element to delete
     * @return response
     * @throws WebApplicationException
     */
    Response delete(String id);

    /**
     * This method returns number of all entities encoded as an XML file as
     * {@code <count>number</count>}.
     *
     * @return number of entities as an XML
     * @throws WebApplicationException
     */
    Response getCount();

    /**
     * This method returns an element by its {@code id}. It returns an entity
     * element itself when an entity of specified {@code id} does not exists.
     *
     * @param id id of an entity to get XML of
     * @return entity encoded as an XML
     * @throws WebApplicationException
     */
    Response getById(String id);

    /**
     * This method returns all entities as an XML file.
     *
     * @return XML representation of all entities
     * @throws WebApplicationException if something goes wrong
     */
    Response getAll();

    /**
     * This method updates an entity.
     *
     * @param data data to update an entity to as a stream
     * @return response
     * @throws WebApplicationException
     */
    Response update(InputStream data);
}
